package cn.sczhyt.modules.szhy.service.impl;

import cn.sczhyt.modules.app.entity.UserEntity;
import cn.sczhyt.modules.szhy.dao.MeetingFileDao;
import cn.sczhyt.modules.szhy.entity.MeetingFileEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.sczhyt.common.utils.PageUtils;
import cn.sczhyt.common.utils.Query;

import cn.sczhyt.modules.szhy.dao.MeetingFileUserDao;
import cn.sczhyt.modules.szhy.entity.MeetingFileUserEntity;
import cn.sczhyt.modules.szhy.service.MeetingFileUserService;
import org.springframework.transaction.annotation.Transactional;


@Service("meetingFileUserService")
public class MeetingFileUserServiceImpl extends ServiceImpl<MeetingFileUserDao, MeetingFileUserEntity> implements MeetingFileUserService {


    @Autowired
    private MeetingFileDao meetingFileDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MeetingFileUserEntity> page = this.page(
                new Query<MeetingFileUserEntity>().getPage(params),
                new QueryWrapper<MeetingFileUserEntity>()
        );

        return new PageUtils(page);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void read(UserEntity user, String fileId) {

        MeetingFileEntity meetingFileEntity = meetingFileDao.selectById(fileId);


        MeetingFileUserEntity meetingFileUserEntity = new MeetingFileUserEntity();
        meetingFileUserEntity.setUserId(user.getUserId());
        meetingFileUserEntity.setFileId(fileId);
        meetingFileUserEntity.setReadState(true);
        meetingFileUserEntity.setMeetingId(meetingFileEntity.getMeetingId());

        this.baseMapper.insert(meetingFileUserEntity);
    }

}